import socketserver
import server
import argparse
import logging

parser = argparse.ArgumentParser()
parser.add_argument('--host',type=str,default='localhost')
parser.add_argument('--port',type=int,default=10930)
parser.add_argument('--intervals',type=float,default=30)
parser.add_argument('--includes',type=int,nargs='+',default=None)
parser.add_argument('--excludes',type=int,nargs='+',default=None)

if __name__ == '__main__':
    args = parser.parse_args()
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO)
    formatter = logging.Formatter('[%(levelname)s:%(asctime)s:%(module)s@%(lineno)s]:%(message)s',
                                  datefmt='%Y-%m-%d %H:%M:%S')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    server.server = server.Server(args.includes,args.excludes)
    logger.info('listening at {}:{}'.format(args.host,args.port))
    with socketserver.UDPServer((args.host,args.port),server.RequestHandler) as ser:
        ser.serve_forever()